package com.ruoyi.web.controller.app.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.exception.base.XException;
import com.ruoyi.framework.web.exception.base.XResult;
import com.ruoyi.im.domain.Friends;
import com.ruoyi.im.mapper.FriendsMapper;
import com.ruoyi.sj.domain.Label;
import com.ruoyi.sj.mapper.LabelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName AppLabelService
 * @Description TODO
 * @Author tyc@yanyu
 * @Date 2018/12/29 0029 16:59
 **/
@Service
public class AppLabelService {
    @Autowired
    private LabelMapper labelMapper;
    @Autowired
    private FriendsMapper friendsMapper;

    /**
     * 新增标签
     *
     * @param label
     * @return
     */
    public Object insertLabel(Label label) {
        return labelMapper.insertLabel(label);
    }

    /**
     * 查询用户标签列表
     *
     * @param memberId
     * @return
     */
    public Object selectLabelList(String memberId) {
        if (StringUtils.isBlank(memberId)) {
            throw new XException("用户ID号不能为空");
        }
        Label label = new Label();
        label.setMemberId(memberId);
        return labelMapper.selectLabelList(label);
    }

    /**
     * 修改标签
     *
     * @param id
     * @return
     */
    public Object updateLabelById(Long id, String title) {
        Label label = new Label();
        label.setTitle(title);
        label.setId(id);
        return labelMapper.updateLabel(label);
    }

    /**
     * 删除标签
     *
     * @param id
     * @return
     */
    public Object deleteLabel(Long id) {
        return labelMapper.deleteLabelById(id);
    }

    /**
     * 向标签中添加用户
     *
     * @return
     */
    public Object insertUsers(String ids,String userId,String friendsUserId) {
        if (StringUtils.isBlank(ids)) {
            throw new XException("标签id不能为空");
        }
        Friends friends = new Friends();
        friends.setLabelId(Long.valueOf(ids));
        friends.setUserId(Long.valueOf(userId));
        friends.setFriendsUserId(Long.valueOf(friendsUserId));
        return friendsMapper.updateFriendsById(friends);
    }
}
